﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;

namespace CoreShop.PrintService
{
    public class PingPrinter
    {
        public bool PingIPAddress(string sIpAddress)
        {
            try
            {
                // 创建 Ping 实例
                using (Ping ping = new Ping())
                {
                    PingReply reply = ping.Send(sIpAddress, 1000); // 1000 毫秒超时时间

                    if (reply.Status == IPStatus.Success)
                    {
                        //Console.WriteLine("Ping 成功。");
                        return true;
                    }
                    else
                    {
                        //Console.WriteLine($"Ping 失败: {reply.Status.ToString()}");
                        return false;
                    }
                }
            }
            catch (Exception ex)
            {
                //Console.WriteLine($"发生异常: {ex.Message}");
                return false;
            }
        }
    }
}
